package org.zzh.springboot.config;

import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
import org.zzh.springboot.interceptor.LoginInterceptor;

@Configuration
public class MvcConfig implements WebMvcConfigurer {

    //扩展视图控制器 映射器
    @Override
    public void addViewControllers(ViewControllerRegistry registry) {
        //浏览器发送/welcome请求 到达welcome页面
//        registry.addViewController("/welcome").setViewName("index");
        registry.addViewController("/toLogin").setViewName("login");
        registry.addViewController("/main").setViewName("main");
        registry.addViewController("/AddUserById").setViewName("add");
        registry.addViewController("/toRegister").setViewName("register");
    }
    //拦截器-登录拦截器
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(new LoginInterceptor()).addPathPatterns("/*")
                .excludePathPatterns("/toLogin","/doLogin","/toRegister", "/doRegister","/index","/captcha");
    }
}
